<?php
namespace Site\Controller;
class LinkController extends CommonController {
    public function index() {
        $data = $this->getPageList(M('Link'),array('sid'=>$this->sid),'sid desc,sort desc');
        $this->display();
    }

    public function add() {
        if(IS_POST) {
            D('Link','Mysql')->addLink(I('post.'));
            $this->success('友链添加成功','/Link');
        }
        $this->display();
    }

    public function update() {
        if(IS_POST) {
            D('Link','Mysql')->updateLink(I('post.'));
            $this->success('友链修改成功','/Link');
        }else {
            $id = I('get.id');
            verify($id,'isID','非法友链ID');

            $linkInfo = M('Link')->find($id);
            verify($linkInfo,'notEmpty','友链不存在');

            if($linkInfo['sid'] != $this->sid) {
                $this->error('请切换网站之后修改');
            }

            $this->assign('linkInfo',$linkInfo);
            $this->display();
        }
    }
}
?>

